<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,initial-scale=1.0,width=device-width" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>Hello APP</title>
    <link rel="stylesheet" type="text/css" href="./css/api.css" />
    <link rel="stylesheet" type="text/css" href="./css/hui.css" />
    <link rel="stylesheet" type="text/css" href="./css/iconfont.css" />
    <style type="text/css">
        html,
        body {
            height: 100%;background-image: url('./image/loginbg5.jpg');background-size:cover;
        }

        .flex-1 {
            -webkit-box-flex: 1;
            -webkit-flex: 1;
        }
        header{position: fixed;height:35px;width: 100%;}
        footer {
            height: 30px;
            width: 100%;
            background-color: #81a9c3;
            color: white;
            line-height: 30px;
            text-align: center;
        }
    </style>
</head>

<body class="wrap">

    <header class="hui-header">
        <div id="hui-back"></div>
        <h1>会员登录</h1>
        <div onclick="saoma2()" class="iconfont iconsaoma" id="hui-saoma"></div>
    </header>

	<div style="height:130px;text-align: center;padding-top:100px;"><img style="width:120px;" src="./image/logo.png"></div>
    <div style="margin:20px 10px;border-radius:5px;" class="hui-form" id="form1">
        <div class="hui-form-items">
        	<div class="hui-form-items-title">用户名</div>
            <input id="username" value="" type="text" class="hui-input hui-input-clear" placeholder="如：" checkType="string" checkData="5,20" checkMsg="用户名应为5-20个字符" />
        </div>
        <div class="hui-form-items">
        	<div class="hui-form-items-title">登录密码</div>
            <input id="password" value="22510" type="password" class="hui-input hui-pwd-eye" placeholder="登录密码" checkType="string" id="pwd" checkData="6,20" checkMsg="密码应为6-20个字符" />
        </div>
    </div>
    <div style="padding:10px; padding-top:10px;">
        <button onclick="login()" type="button" class="hui-button hui-button-large hui-primary" id="submit" style="width:60%;float:left;">立即登录</button>
        <button onclick="reg()" type="button" class="hui-button hui-button-large hui-danger" id="submit" style="width:38%;float:left;margin-left:2%;">注册</button>
    </div>

</body>

</html>
<script src="./script/hui.js" type="text/javascript" charset="utf-8"></script>
<script src="./script/hui-swipe.js" type="text/javascript" charset="utf-8"></script>
<script src="./script/api.js" type="text/javascript" charset="utf-8"></script>
<script src="./script/stm.js" type="text/javascript" charset="utf-8"></script>

<script type="text/javascript">

apiready = function () {



    $api.setStorage('weburl','http://122.114.248.166:88/');
    $api.setStorage('appid','wx678cde1c9349bce9');
    $api.setStorage('geturl',$api.getStorage('weburl')+'index.php?s=hospital&appid='+$api.getStorage('appid'));

    worknet()

    var header = $api.dom('header'); // 获取 header 标签元素
    var footer = $api.dom('footer'); // 获取 footer 标签元素



    // 1.修复开启沉浸式效果带来的顶部Header与手机状态栏重合的问题，最新api.js方法已支持适配iPhoneX；
    // 2.默认已开启了沉浸式效果 config.xml中 <preference name="statusBarAppearance" value="true"/>
    // 3.沉浸式效果适配支持iOS7+，Android4.4+以上版本
    var headerH = $api.fixStatusBar(header);
    // 最新api.js为了适配iPhoneX增加的方法，修复底部Footer部分与iPhoneX的底部虚拟横条键重叠的问题；
    var footerH = $api.fixTabBar(footer);

    $api.setStorage('headerH',headerH);
    $api.setStorage('footerH',footerH);

    /*api.openFrame({
        name: 'login_win',
        url: 'html/my/login_win.html',
        bounces: false,
        rect: { // 推荐使用Margin布局，用于适配屏幕的动态变化
            marginTop: 0, // main页面距离win顶部的高度
            marginBottom: 0, // main页面距离win底部的高度
            w: 'auto' // main页面的宽度 自适应屏幕宽度
        }
    });*/
    islogin(2)



};


function reg(){
    api.openFrame({
        name: 'reg',
        url : './reg.html',
        bounces: false,
        rect: { // 推荐使用Margin布局，用于适配屏幕的动态变化
            marginTop: 0, // main页面距离win顶部的高度
            marginBottom: 0, // main页面距离win底部的高度
            w: 'auto' // main页面的宽度 自适应屏幕宽度
        }
    });
}

function login(){

    var username  = hui("#username").val();
    var password = hui("#password").val();

    if (username == '') {
        api.toast({ msg:'用户名不能为空',location:'top' })
        return false;
    }
    if (password == '') {
        api.toast({ msg:'密码不能为空',location:'top' })
        return false;
    }

    api.ajax({
        url: $api.getStorage('geturl')+'&c=ajaxmember&a=login',
        method: 'post',
        data: {
            values: {
                username:username,
                password:password
            }
        }
    },function(ret, err){
        if (ret) {
            if (ret.status==1) {

                //console.log(JSON.stringify(ret))
                //患者
                if(ret.data.flag==1){
                    $api.setStorage('userid',ret.data.userid);
                    $api.setStorage('username',ret.data.name);
                    $api.setStorage('docid',ret.data.docid);
                    $api.setStorage('hospid',ret.data.hospid);
                    $api.setStorage('health',ret.data.health);
                    $api.setStorage('province',ret.data.province);
                    $api.setStorage('city',ret.data.city);
                    $api.setStorage('area',ret.data.area);
                }

                //医生
                if(ret.data.flag==2){
                    $api.setStorage('userid',ret.data.userid);
                    $api.setStorage('username',ret.data.name);
                    $api.setStorage('docid',ret.data.userid);
                    $api.setStorage('hospid',ret.data.hospid);
                    $api.setStorage('province',ret.data.province);
                    $api.setStorage('city',ret.data.city);
                    $api.setStorage('area',ret.data.area);
                }
                $api.setStorage('flag',ret.data.flag);

                api.toast({ msg:ret.tip,location:'top' })
                setTimeout("tohome()",1000)
            }else{
                api.toast({ msg:ret.tip,location:'top' })
            }
        } else {
            alert( JSON.stringify( err ) );
        }
    });


}

function tohome(){
    if($api.getStorage('flag')==2){
        toDetails('./html/doctor/home/','home',0)
    }else{
        toDetails('./html/patient/home/','home',0)
    }
}
</script>
